Field of the Invention
The present invention relates to a method and computer system for automatically generating code from block diagrams, the code, for example, being used in electronic control units.
Description of the Background Art
Electronic control units (ECUs) are ubiquitous especially in automotive applications; generally, they may contain a processor, for example, a microcontroller, one or more sensor interfaces and one or more circuits to control an actuator. Current parameters of a physical process are determined using the signals of the one or more sensors connected to the sensor interfaces. Based on a predefined control strategy, the processor may control the one or more circuits to apply the actuators in order to influence the physical process. In a particular example, an ECU may be used to perform anti-lock braking, with a sensor measuring the wheel velocity and a magnetic valve reducing the pressure in the corresponding wheel brakes.
In order to speed up the development process for ECUs, control strategies are developed using block diagrams in a technical computing environment (TCE), which allows for tracing the temporal behavior of a physical system described by one or more blocks in the block diagram. One particular example of a TCE is MATLAB/Simulink of The MathWorks.
The document “Production Quality Code Generation from Simulink Block Diagrams”, Proceedings of the 1999 IEEE International Symposium on Computer Aided Control System Design, Kohala-Coast, Hawai'i, USA, by H. Hanselmann et al. describes a system for automatically generating production code based on a block diagram containing one or more blocks that specify the functionality of the program. The program may be a control program for an ECU, the control program implementing the desired control strategy.
When an existing ECU can be used as a basis for developing a new ECU or a single function of an existing control program needs to be modified, a method known as bypassing is commonly used. Generally, the ECU remains in the control loop and the existing control program is executed; however, the original code for the selected function is bypassed. The sensor inputs and/or current variable values of the ECU are collected and used as an input for a new function; the output values of the new function are then transferred to the respective addresses on the ECU.
In so-called external bypassing, a rapid control prototyping (RCP) system running the new function is connected to the ECU. While this allows for computationally expensive new functions, it cannot provide an answer on the question if the new function can be executed in real-time on the existing ECU.
Internal bypassing, also known as on-target bypassing, refers to running the new function on the microcontroller in the ECU. The ECU still executes any other function that is present in the original control program. The patent EP 2881858 B1, “Method for modifying the software in the memory of an electronic control device”, discloses a method for internal bypassing; the original binary code of the control program is modified to accommodate service functions that are executed before and after the selected function. Internal bypassing requires code specifically adapted to the hardware and software of the current ECU. Therefore, even when a block diagram of the control program exists, cumbersome manual adaptions are necessary.
The U.S. Pat. No. 8,701,081 B2, “Hardware specific code generation”, describes a method for adapting functions with a specific argument pattern to a processor architecture of the target platform based on a hardware-specific library. This allows e.g. for replacing all addition operators with integer arguments by a hardware-specific function. However, for internal bypassing, the generated code needs to be adapted to the current version of the ECU firmware.
Thus, improved methods for generating program code, in particular a flexible way for generating program code adapted to a specific hardware and software environment, are desired.